package com.simon.seckill.task;

import com.simon.seckill.Entities.Product;
import com.simon.seckill.cache.GoodsRedisStoreCache;
import com.simon.seckill.dao.ProductDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商品库存初始化任务
 * */
@Component
public class GoodRedisStoreInitTask {
    @Autowired
    private ProductDao productDao;

    @Autowired
    private GoodsRedisStoreCache goodsRedisStoreCache;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void doInit() {
        List<Product> goods = productDao.selectAllProducts();
        for (Product good : goods) {
            goodsRedisStoreCache.doInit(good);
        }
    }
}
